package com.sth.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.sth.common.result.Result;
import com.sth.entity.People;
import com.sth.entity.Ranking;
import com.sth.service.PeopleService;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sith
 * @since 2024-07-12
 */
@RestController
@RequestMapping("/sth/people")
public class PeopleController {

    @Autowired
    private PeopleService peopleService;

    @ApiOperation(value = "获取数据")
    @GetMapping("/getList")
    public Result getList() {
        List<People> list = peopleService.getBaseMapper().selectList(new QueryWrapper<>());
        return Result.ok(list);
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody People people) {
        boolean save = peopleService.save(people);
        return Result.ok(save);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        peopleService.removeById(id);
        return Result.ok();
    }
}

